<?php

/**
 * View handler
 * Displays the view as JSON data
 *
 * @access Ben Rowe
 */
class ViewJSON extends ViewBase
{

	/**
	 * Contains the logic to execute the view
	 * Called by the ViewBase
	 * This class executes the _render() method which must be defined within the
	 * actual view class
	 *
	 * @access private
	 * @return ViewJSON
	 */
	function _exec()
	{
		$obj = $this->_render();
		echo $this->_toJSON($obj);
	}
	
	/**
	 * Converts the provided variable into a JSON formatted string.
	 * The provided variable may only be a object or an array
	 *
	 * @access private
	 * @param mixed $object
	 * @return null
	 */
	function _toJSON($object)
	{
		require_once 'lib'.DS.'JSON'.EXT;
		$json = new JSON;
		echo $json->serialize($object);
	}
	
}

?>